package com.yunduansing.demo.web.account;

import java.util.List;

import com.yunduansing.demo.model.account.LoginModel;
import com.yunduansing.demo.model.account.LoginUserModel;
import com.yunduansing.demo.model.common.ResponseModel;
import com.yunduansing.demo.service.AccountService;
import com.yunduansing.demo.service.UserService;
import com.yunduansing.demo.service.impl.AuthUserService;
import com.yunduansing.demo.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Api(tags = "账户相关")
public class AccountController extends BaseController {
    @Autowired
    private AccountService service;
    @Autowired
    private UserService userService;

    @PostMapping("/initPassword")
    @ApiOperation("初始化密码")
    public ResponseModel initPassword(@RequestBody List<Integer> userIds){
        var result=userService.initPassword(userIds);
        if(result) return ResponseModel.ok();
        return ResponseModel.error("操作失败。");
    }

    @GetMapping("/account/code")
    @ApiOperation("获取验证码")
    public String getVerificationCode(){
        return this.getPassport().getFullName()+"1234";
    }

    @GetMapping("/account/info")
    @ApiOperation("获取登录用户信息")
    public ResponseModel<LoginUserModel> getInfo(){
        var user=this.getPassport();
        var ruser=service.login(user.getUsername());
        ruser.setPassword("");
        return ok(ruser);
    }
}
